package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.data.Bean.detail.CodeItem;
import cn.kooki.app.duobao.util.TimeUtils;

/**
 * Created by xiong on 2015/12/31.
 */
public class CodeListAdapter extends BaseAdapter {

    private final boolean isother;
    private ArrayList<CodeItem> datas;
    private final Context context;

    public CodeListAdapter(Context context, ArrayList<CodeItem> datas, boolean isother) {
        this.context = context;
        this.datas = datas;
        this.isother = isother;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        CodeItem item = datas.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_ordercodelist_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.txtCodeDetail.setText(isother ? "查看TA的号码" : "查看我的号码");
        viewHolder.txtPayTime.setText(TimeUtils.getTime(item.time));
        viewHolder.txtPayCount.setText(item.gonumber);
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'layout_ordercodelist_item.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.txtPayTime)
        TextView txtPayTime;
        @Bind(R.id.labelCount)
        TextView labelCount;
        @Bind(R.id.txtPayCount)
        TextView txtPayCount;
        @Bind(R.id.imgMulti)
        ImageView imgMulti;
        @Bind(R.id.txtMultiDetail)
        TextView txtMultiDetail;
        @Bind(R.id.txtCodeDetail)
        TextView txtCodeDetail;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
